class Work < ActiveRecord::Base
  has_many :pictures, :dependent => :destroy
  has_many :work_comments, :dependent => :destroy
  
  has_many :favorite_works
  has_many :lovers,
           :through => :favorite_works,
           :source => :user
  belongs_to :user
  belongs_to :retype
  accepts_nested_attributes_for :pictures, :allow_destroy => true
  validates_presence_of :title, :content, :message => "不能为空"
  validates_presence_of :pictures, :message => "至少一张"

  define_index do
    indexes title
    indexes content
    has user_id, created_at, updated_at
  end
  
  HUMANIZED_COLLUMNS = {:pictures => "图片", :title => "标题", :desc => '描述'}
  def self.human_attribute_name(attribute)
    HUMANIZED_COLLUMNS[attribute.to_sym] || super
  end
  
end
